define([], function () {
  'use strict';
  /**
   * 获取当前月期号
   * 返回格式: YYYY-mm
   * */
  function getCurrentMonthIssue(date) {
    let month = parseInt(date.getMonth() + 1);
    if (month < 10) {
      month = '0' + month
    }
    return date.getFullYear() + "-" + month;
  }

  /**
   * 获取当前的日期
   * 返回格式: YYYY-mm-dd
   * */
  function getCurrentDate(date) {
    let month = parseInt(date.getMonth() + 1);
    let day = date.getDate();
    if (month < 10) {
      month = '0' + month
    }
    if (day < 10) {
      day = '0' + day
    }
    return date.getFullYear() + '-' + month + '-' + day;
  }

  /**
   * 获取本周的第一天
   * 返回格式: YYYY-mm-dd
   *    例子: 当日为: 2020-11-27
   *      返回日期为: 2020-11-23
   * */
  function getCurrentWeekFirstDay(date) {
    let weekFirstDay = new Date(date - (date.getDay() - 1) * 86400000)
    let firstMonth = Number(weekFirstDay.getMonth()) + 1

    if (firstMonth < 10) {
      firstMonth = '0' + firstMonth
    }
    let weekFirstDays = weekFirstDay.getDate();
    if (weekFirstDays < 10) {
      weekFirstDays = '0' + weekFirstDays;
    }
    return weekFirstDay.getFullYear() + '-' + firstMonth + '-' + weekFirstDays;
  }

  /**
   * 获取本周的最后一天
   * 返回格式: YYYY-mm-dd
   *    例子: 当日为: 2020-11-27
   *      返回日期为: 2020-11-29
   * */
  function getCurrentWeekLastDay(date) {
    let weekFirstDay = new Date(date - (date.getDay() - 1) * 86400000)
    let weekLastDay = new Date((weekFirstDay / 1000 + 6 * 86400) * 1000)
    let lastMonth = Number(weekLastDay.getMonth()) + 1
    if (lastMonth < 10) {
      lastMonth = '0' + lastMonth
    }
    let weekLastDays = weekLastDay.getDate();
    if (weekLastDays < 10) {
      weekLastDays = '0' + weekLastDays;
    }
    return weekFirstDay.getFullYear() + '-' + lastMonth + '-' + weekLastDays;
  }

  /**
   * 获取当前月的第一天
   * 返回格式: YYYY-mm-dd
   *    例子: 当日为: 2020-11-27
   *      返回日期为: 2020-11-01
   * */
  function getCurrentMonthFirstDay() {
    let date = new Date();
    date.setDate(1);
    let month = parseInt(date.getMonth() + 1);
    let day = date.getDate();
    if (month < 10) {
      month = '0' + month
    }
    if (day < 10) {
      day = '0' + day
    }
    return date.getFullYear() + '-' + month + '-' + day;
  }

  /**
   * 获取当前月的最后一天
   * 返回格式: YYYY-mm-dd
   *    例子: 当日为: 2020-11-27
   *      返回日期为: 2020-11-30
   * */
  function getCurrentMonthLastDay() {
    let date = new Date();
    let currentMonth = date.getMonth();
    let nextMonth = ++currentMonth;
    let nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
    let oneDay = 1000 * 60 * 60 * 24;
    let lastTime = new Date(nextMonthFirstDay - oneDay);
    let month = parseInt(lastTime.getMonth() + 1);
    let day = lastTime.getDate();
    if (month < 10) {
      month = '0' + month
    }
    if (day < 10) {
      day = '0' + day
    }
    return date.getFullYear() + '-' + month + '-' + day;
  }

  return {
    getCurrentMonthIssue: getCurrentMonthIssue,
    getCurrentDate: getCurrentDate,
    getCurrentWeekFirstDay: getCurrentWeekFirstDay,
    getCurrentWeekLastDay: getCurrentWeekLastDay,
    getCurrentMonthFirstDay: getCurrentMonthFirstDay,
    getCurrentMonthLastDay: getCurrentMonthLastDay,
  }

});